import {ModalForm, ProFormText} from "@ant-design/pro-components";
import React from "react";
import {addBusinessPage} from "@/services/wms-dev-tool/business-page-list";
import {message} from "antd";
import {useRequest} from "@@/plugin-request";

const AddForm = (props: any) => {
  const {run} = useRequest(addBusinessPage, {
    manual: true,
    onSuccess: () => {
      props.handleAddFormOpen(false);
      props.ok()
    },
    onError:(error:any)=>{
      message.error(error.message)
    }
  })
  return (
    <ModalForm
      initialValues={{
        name:'',
        code:''
      }}
      modalProps={{
        destroyOnClose: true
      }}
      title={<span>新增页面</span>}
      width="400px"
      open={props.addFormOpen}
      onOpenChange={props.handleAddFormOpen}
      onFinish={async (params:API.BusinessPage) => {
        run(params);
      }}
    >
      <ProFormText
        rules={[
          {
            required: true,
            message: (
              <span>名称是必填项</span>
            ),
          },
        ]}
        placeholder={"请输入名称"}
        label={<span>名称</span>}
        width="md"
        name="name"
      />
      <ProFormText
        rules={[
          {
            required: true,
            message: (
              <span>编码是必填项</span>
            ),
          },
        ]}
        width="md"
        label={<span>编码</span>}
        placeholder={"请输入编码"}
        name="code"/>
    </ModalForm>
  )
}
export default AddForm
